package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageDTO;
import com.sky.entity.Dish;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DishMapper {

    //通过分类id统计
    String count = "SELECT count(*) FROM dish WHERE category_id=#{categoryId}";
    @Select(count)
    Integer count(Long categoryId);

    // 根据菜品名称查询
    @Select("select * from dish where name=#{name}")
    Dish getByName(String name);

    // 新增菜品
    @AutoFill("insert")
    void insert(Dish dish);
    // 条件查询菜品列表
    List<DishVO> getList(DishPageDTO dishPageDTO);

    // 根据id查询
    @Select("select * from dish where id=#{id}")
    Dish getById(Long id);

    // 修改菜品
    @AutoFill("update")
    void updateById(Dish dish);

    // 删除菜品
    @Delete("delete from dish where id=#{id}")
    void deleteById(Long id);
    @Select("select count(*) from dish where status = #{status} and id in(\n" +
            "    select dish_id from setmeal_dish where setmeal_id = #{setmealId})")
    Long countBySidAndStatus(Long setmealId, int status);
}

